package com.server.questionbank.snframe.service.CourseService.Impl;

import com.server.questionbank.snframe.domain.QuestionBank.Question;
import com.server.questionbank.snframe.mapper.Course.TQuestionMapper;
import com.server.questionbank.snframe.service.CourseService.TQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TQuestionServiceImpl implements TQuestionService {
    @Autowired
    private TQuestionMapper tQuestionMapper;

    // 根据题目 ID 查询问题
    @Override
    public List<Question> getQuestionByExercisesId(Long exercisesId) {
        return tQuestionMapper.getQuestionByExercisesId(exercisesId);
    }

    // 添加问题
    @Override
    public Boolean addQuestion(List<Question> question) {
        for (Question q : question)
            if (tQuestionMapper.addQuestion(q) <= 0) return false;
        return true;
    }

    // 更新问题
    @Override
    public Boolean updateQuestion(List<Question> question) {
        for (Question q : question)
            if (tQuestionMapper.updateQuestion(q) <= 0) return false;
        return true;
    }

    // 删除问题
    @Override
    public Boolean deleteQuestion(List<Long> questionId) {
        for (Long id : questionId)
            if (tQuestionMapper.deleteQuestion(id) <= 0) return false;
        return true;
    }

    // 根据exercisesIds和questionType查询
    @Override
    public List<Question> findByExercisesIdsAndType(List<Long> exercisesId, String questionType) {
        return tQuestionMapper.findByExercisesIdsAndType(exercisesId,questionType);
    }
}
